<!doctype html>
<html>

	<head>
		<meta charset="utf-8">
		<title>注册</title>
		<meta name="viewport" content="width=device-width,initial-scale=1,minimum-scale=1,maximum-scale=1,user-scalable=no" />
		<link href="css/mui.css" rel="stylesheet" />
		<link rel="stylesheet" type="text/css" href="css/common.css"/>
		<link rel="stylesheet" type="text/css" href="css/index.css"/>
	</head>
	<body class="bg_ff">
	<header class="mui-bar mui-bar-nav">
	    <a class="mui-action-back mui-icon mui-icon-left-nav mui-pull-left"></a>
	    <h1 class="mui-title">注册</h1>
	</header>
	<div class="mui-content bg_ff">
	    <div class="text-center">
		<img class="logo mg_top5" src="images/logo.png"/>
	</div>
	
	<div class="form">
		<div class="input_list">
			<input type="text" name="" id="name" value="" placeholder="请输入昵称"/>
		</div>
		<div class="input_list relative clearfix">
			<span class="flex ">
				<select name=""  id="select">
					<option value="1">男</option>
					<option value="2">女</option>
				</select>
				<img width="15" height="8" class="vertical-align_m mg_top15" src="images/icon_down.png"/>
			</span>
			
		</div>
		<div class="input_list">
			<input type="number" name="" id="age" value="" placeholder="请输入年龄"/>
		</div>
		<div class="input_list">
			<input type="text" name="" id="phone" value="" placeholder="请输入手机号"/>
		</div>
		<div class="input_list">
			<input type="password" name="" id="password" value="" placeholder="请输入密码"/>
		</div>
		<div class="input_list">
			<input type="text" name="" id="yq_code" value="" placeholder="请输入邀请码"/>
		</div>
		<div class="input_list code_login relative active">
			<input type="text" name="" id="getcode" value="" placeholder="请输入验证码"/>
			<input type="text" name="" id="" class="getcode absolute" value="获取验证码" readonly="readonly" />
		</div>
		<p class="text-center mg_top20"><a href="javascript:void(0);" class="big_btn" onclick="reg()">注册></a></p>
		<!--//javascript:void(0);-->
	</div>
	
	<p class="xy text-center mg_top10 padding_tb20">
			<label for="checkbox" class="label"><img src="images/check_s.png"/></label>我同意
			<a href="codeRule.html?type=1">《拍拍拍用户使用协议》</a>
			<input type="checkbox" name="" checked="checked" id="checkbox" hidden="hidden" value="" />
			
		</p>

	</div>
	<div class="msg-spring"></div>
		
		<script src="js/mui.js"></script>
		<script src="js/jquery-1.7.1.min.js" type="text/javascript" charset="utf-8"></script>
		<script src="js/login.js" type="text/javascript" charset="utf-8"></script>
		<script src="http://pv.sohu.com/cityjson?ie=utf-8"></script>
		
		       
		
		<script type="text/javascript">
			mui.init()
				console.log(returnCitySN )
			   var cid =returnCitySN.cid
			   var cname =returnCitySN.cname
				$('#checkbox').click(function(){
					var flage = $("input[type='checkbox']").is(':checked')
					console.log(flage)
					if(flage==true){
						$(".xy").children('label').find('img').attr('src','images/check_s.png')
					}else{
						$(".xy").children('label').find('img').attr('src','images/check.png')
					}
				})
				
				$('.getcode').click(function(){
					
					$.ajax({
						type:"post",
						url:urlcom + "sms/getSmsCode",
						async:true,
						dataType:'json',
						data:{
							type:1,
							phone:$('#phone').val()
						},
						success:function(res){
							if(res.code==0){
								 msg('验证码发送成功')
								settime() 
							}
							console.log(res)
						}
					});
				})
					
				$('#getcode').blur(function(){
					var _getcode = $('#getcode').val()
					console.log(_getcode)
					if(_getcode){
						$.ajax({
						type:"post",
							url:urlcom + "sms/validateSms",
							async:true,
							dataType:'json',
							data:{
								type:1,
								phone:$('#phone').val(),
								code:$('#getcode').val()
							},
							success:function(res){
								if(res.code==0){
									 msg('验证码发送成功')
									settime() 
								}else{
									 msg(res.msg)
								}
								console.log(res)
							}
						});
					}else{
						msg('请输入验证码')
						return false;
					}
					
					
				})
				
				function reg(){
			    	
			    	
					var _age = $('#age').val()
					console.log(_age)
					var _phone = $('#phone').val()
		            var _password = $('#password').val()
					var _getcode = $('#getcode').val()
					
					
					if(_age > 40 || _age <15){
						msg('年龄在16-40之间')
						return false;
					}
					
					var flage = $("input[type='checkbox']").is(':checked')
					if(flage==false){
						msg('请选择服务协议')
						return false;
					}
					$('.gif').show()
					$.ajax({
						type:"post",
						url:urlcom + "user/register",
						async:true,
						dataType:'json',
						data:{
							name:$('#name').val(),
							phone:$('#phone').val(),
							password:_password,
							inviteCode:$('#yq_code').val(),
							cityCode:cid,
							sex:$("#select option:selected").val(),
							age:$('#age').val(),
						},
						success:function(res){
								$('.gif').hide()
							if(res.code==0){
								msg('注册成功')
								setTimeout(function(){
									window.location.href='login.html'
								},1000)
							}else{
								msg(res.msg)
							}
							
						}
					});
				}

		</script>
	</body>

</html>
